﻿using Peter.Common;

namespace Peter.Sdw.Data
{
   /// <summary>
   /// Data object for a link.
   /// </summary>
   public class Link : ViewModelBase
   {
      private int m_EndIndex;
      private int m_StartIndex;
      private bool m_NewWindow;
      private string m_LinkUrl;
      private string m_DisplayText;

      /// <summary>
      /// Gets or Sets the id.
      /// </summary>
      public int Id { get; set; }

      /// <summary>
      /// Gets or Sets the starting index.
      /// </summary>
      public int StartIndex
      {
         get { return this.m_StartIndex; }
         set
         {
            this.m_StartIndex = value;
            this.RaisePropertyChanged ("StartIndex");
            this.UpdateDisplayText ();
         }
      }

      /// <summary>
      /// Gets or Sets the ending index.
      /// </summary>
      public int EndIndex
      {
         get { return this.m_EndIndex; }
         set
         {
            this.m_EndIndex = value;
            this.RaisePropertyChanged ("EndIndex");
            this.UpdateDisplayText ();
         }
      }

      /// <summary>
      /// Gets or Sets if this will open in a new window.
      /// </summary>
      public bool NewWindow
      {
         get { return this.m_NewWindow; }
         set
         {
            this.m_NewWindow = value;
            this.RaisePropertyChanged ("NewWindow");
         }
      }

      /// <summary>
      /// Gets or Sets the url.
      /// </summary>
      public string Url
      {
         get { return this.m_LinkUrl; }
         set
         {
            this.m_LinkUrl = value;
            this.RaisePropertyChanged ("Url");
            this.UpdateDisplayText ();
         }
      }

      /// <summary>
      /// Gets or Sets how to display this style.
      /// </summary>
      public string DisplayText
      {
         get { return this.m_DisplayText; }
         set
         {
            this.m_DisplayText = value;
            this.RaisePropertyChanged ("DisplayText");
         }
      }

      /// <summary>
      /// Updates the display text.
      /// </summary>
      private void UpdateDisplayText ()
      {
         this.DisplayText = string.Format ("[{0} - {1}] {2}", this.StartIndex, this.EndIndex, this.Url);
      }
   }
}
